<template>
	<view class="tar-bar">
		<view :class="{'active': value === index}" 
			v-for="(bar, index) in tabList" :key="index"
			@click="changeBar(index)">
				{{bar.name}}
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			value: {
				type: Number,
				default: 0
			},
      tabList: {
        type: Array,
        default: () => [
					{ id: 1, name: '课程' },
					{ id: 2, name: '文章' },
					{ id: 3, name: '问答' }
				]
      }
		},
		data() {
			return {
				
			}
		},
		methods: {
			changeBar(index) {
				// this.tabList.forEach(item => item.active = bar.id === item.id)
				if (this.value !== index) {
					this.$emit('input', index)
				}
			}
		}
	}
</script>

<style lang="scss">
	.tar-bar {
		display: flex;
		justify-content: space-around;
		height: 80rpx;
		border-bottom: 1px solid #efeff4;
		view {
			position: relative;
			line-height: 80rpx;
			&::after {
				position: absolute;
				content: '';
				width: 0;
				height: 0;
				border-bottom: 6rpx solid transparent;
				border-radius: 20rpx;
				left: 50%;
				bottom: 6rpx;
				transform: translateX(-50%);
				transition: .3s;
				
			}
		}
		.active {
			color: $mxg-text-color-blue;
			&:after {
        border-bottom-color: $mxg-text-color-blue;
				width: 60rpx;
			}
		}
	}
</style>
